// 引入express模块
const express = require('express');
// 用app调用express
const app = express();

// 可以让后端接受post请求的中间件,npm install body-parser
const bodyparser = require('body-parser')
app.use(bodyparser.json())
app.use(bodyparser.urlencoded({ extended: true }));
// 可以让前端跨域的中间件
app.use(function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*')
    res.header('Access-Control-Allow-Headers', 'Content-type')
    res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
    next();
})



const router = require('./router');
app.use('/', router)

app.listen(3000, () => {
    console.log('服务器启动成功!!!');
});